/* Copyright (C) 2010 Fredrique Samuels, fredriquesamuels@gmail.com 

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "string.h"


#include <assert.h>

namespace tri {

TString::TString(): m_Value(""){}
	
TString::TString(std::string s): m_Value(s){}

TString::TString(char* s) : m_Value(s){}

TString::TString(TString& s) : m_Value( std::string( s.m_Value.c_str() )){}


std::string TString::getValue() const{
	return m_Value;
}

std::string TString::toString() const{
	std::string out = "TString Value=";
	out += "\"" + m_Value + "\""+ tri::utils::getFormatString(" lenght=%u",m_Value.size());
	return out;
}

bool TString::isNumber() const{
	return tri::utils::isNumber(m_Value);
}

int TString::toInteger() const{
	if( isNumber() ){
		return tri::utils::string2Int(c_str());
	}
	
	return 0;
}

const char* TString::c_str() const{
	return m_Value.c_str();
}

float TString::toFloat() const{
	return tri::utils::string2Float(c_str());
}

void TString::clear(){
	m_Value = "";
}

TString& TString::operator=(const tri::TString &s){
	this->m_Value = s.m_Value;
	return *(this);
}

TString& TString::operator=(const std::string &s){
	this->m_Value = s;
	return *(this);
}

TString& TString::operator=(const char* s){
	this->m_Value = s;
	return *(this);
}

TString& TString::operator=(const float &s){
	this->m_Value = tri::utils::float2String(s);
	return *(this);
}

TString& TString::operator+=(const tri::TString &s){
	this->m_Value += s.m_Value;
	return *(this);
}

TString& TString::operator+=(const std::string &s){
	this->m_Value += s;
	return *(this);
}

TString& TString::operator+=(const char* s){
	this->m_Value += s;
	return *(this);
}

TString& TString::operator+=(const float s){
	this->m_Value += tri::utils::float2String(s);
	return *(this);
}

std::ostream& operator<<( std::ostream& out, const tri::TString& v){
	out<<v.getValue();
	return out;
}

bool TString::startsWith(std::string ss) const{
	return tri::utils::startsWith(this->m_Value, ss);
}

bool TString::endsWith(std::string ss) const{
	return false;
}

bool TString::operator==(const tri::TString &s){
	return this->m_Value.compare(s.m_Value) == 0;
}

}
